#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#define BUFFER_SIZE 8
int main(int argc , char* argv[]){
	if(argc != 3){
		perror("argc NO");	
		exit(1);
	}
	int fd=open(argv[1],O_RDWR); 
	int wfd=open(argv[2],O_RDWR | O_CREAT | O_APPEND,700);
	if(fd==-1){
		perror("argv[1]");
		exit(1);
	}
	if(wfd==-1){
		perror("argv[2]");
		exit(1);
	}
	char buffer[BUFFER_SIZE];
	while(1){
		ssize_t bytes=read(fd,buffer,BUFFER_SIZE);	
		if(bytes==-1){
			perror("Read failure:");
			exit(1);
		}else if(bytes==0){
			break;
		}
		ssize_t wbytes =write(wfd,buffer,bytes);
		if(wbytes == -1){
			perror("Write failure:");
		}
	}
	close(fd);
	close(wfd);
	return 0;
}
